package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.service.PermissionService;
import com.itheima.service.RoleService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//权限管理
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Reference//查找服务
    private PermissionService permissionService;

    //新增权限管理项
    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission){
        try{
            permissionService.add(permission);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return new Result(false, "添加权限管理项失败");
        }
        return  new Result(true, "添加权限管理项成功");
    }

    //权限管理项分页查询
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = permissionService.pageQuery(queryPageBean);
        return pageResult;
    }

    @RequestMapping("/findAll")
    public Result findAll(){
        try{
            List<Permission> list = permissionService.findAll();
            return  new Result(true, "获取权限管理项成功",list);
        }catch (Exception e){
            e.printStackTrace();
            //服务调用失败
            return new Result(false, "获取权限管理项失败");
        }
    }
}
